/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T6A_ITT_sensitivity.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
	Table A6: ITT Extra sensitivity analysis - all outcomes
*******************************************************************************/


	local child "zptevir_irtscore2 zcog_index zsoc_index" 
	#delimit;
	foreach var of local child {;
				
				* PANEL 1: ITT with Age and Gender and SES;
					xi: reg `var' i.TIPO $Xvar1 i.CENTRO_SALUD, cl(FOLIO_UC);
					estimates store `var'_itt1;
				    test _ITIPO_2 ==_ITIPO_3;
					estadd scalar pb=r(p);

				* PANEL 2: ITT with Age and Gender and interviewer fe-; 	  
					xi: xtreg `var' i.TIPO $Xvar1 i.APLICADOR, fe i(CENTRO_SALUD);
					estimates store `var'_itt2;
				    test _ITIPO_2 ==_ITIPO_3;
					estadd scalar pb=r(p);						
	};


	#delimit cr


	local parental "zfbeh_gsem zfbel_gsem zfwb " 
	#delimit;
	foreach var of local parental {;
				
					
				* PANEL 3: ITT with Age and Gender and SES;
					xi: reg `var' i.TIPO $Xvar1 i.CENTRO_SALUD if x==1, cl(FOLIO_UC);
					estimates store `var'_itt1;
					test _ITIPO_2 ==_ITIPO_3;
					estadd scalar pb=r(p);	
					
				* PANEL 4: with Age and Gender and interviewer fe -; 	  
					xi: xtreg `var' i.TIPO $Xvar1 i.APLICADOR if x==1, fe i(CENTRO_SALUD);
					estimates store `var'_itt2;
					test _ITIPO_2 ==_ITIPO_3;
					estadd scalar pb=r(p);	
	};


	#delimit cr
	***  Tables ITT Outcomes

			
		esttab zptevir_irtscore2_itt1 zcog_index_itt1 zsoc_index_itt1  /*
		*/ using "${out_tables}/appendix/T6A_ITT_sensitivity.csv", replace f		  /* 
		*/ keep(_ITIPO_2 _ITIPO_3) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2 N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	  /*
		*/ mtitles("Vocabulary Index""Exec. Function Index""Socioemotional Index" ) /*
		*/ title("Child Outcome (1): (age/gender) + Interviewer's fixed  effects") 	varlabels(_ITIPO_2 "NEP-B" _ITIPO_3 "NEP-I")

		esttab zptevir_irtscore2_itt2 zcog_index_itt2 zsoc_index_itt2 /*
		*/ using "${out_tables}/appendix/T6A_ITT_sensitivity.csv", append f		  /* 
		*/ keep(_ITIPO_2 _ITIPO_3) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2 N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	  /*
		*/ mtitles("Vocabulary Index""Exec. Function Index""Socioemotional Index" ) /*
		*/ title("Child Outcome (2): (age/gender) + Std. errors clustered at the household level") 	varlabels(_ITIPO_2 "NEP-B" _ITIPO_3 "NEP-I")
		
		
	

	esttab zfbeh_gsem_itt1 zfbel_gsem_itt1   zfwb_itt1                   /*
		*/ using "${out_tables}/appendix/T6A_ITT_sensitivity.csv", append f		  /* 
		*/ keep(_ITIPO_2 _ITIPO_3) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2 N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	/*
		*/ mtitles("Behavioral Index""Beliefs Index""Well-being Index" ) /*
		*/ title("Parental Outcome (1): (age/gender) + Interviewer's fixed  effects") 	varlabels(_ITIPO_2 "NEP-B" _ITIPO_3 "NEP-I")

		esttab zfbeh_gsem_itt2 zfbel_gsem_itt2   zfwb_itt2        					  /*
		*/ using "${out_tables}/appendix/T6A_ITT_sensitivity.csv", append f		  /* 
		*/ keep(_ITIPO_2 _ITIPO_3) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2 N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	/*
		*/ mtitles("Behavioral Index""Beliefs Index""Well-being Index" ) /*
		*/ title("Parental Outcome (2): (age/gender) + Std. errors clustered at the household level") 	/*
		*/ varlabels(_ITIPO_2 "NEP-B" _ITIPO_3 "NEP-I")
	
	

		
* End of dofile 

	
